class Solution(object):
    def validIPAddress(self, queryIP):
        """
        :type queryIP: str
        :rtype: str
        """
        if '.' in queryIP:
            if ':' in queryIP:
                return 'Neither'
            else:
                s = queryIP.split('.')
                if len(s) != 4:
                    return 'Neither'
                for i in range(4):
                    if not s[i]:
                        return 'Neither'
                    for k in range(len(s[i])):
                        if not '0' <= s[i][k] <= '9':
                            return 'Neither'
                    s_value = int(s[i])
                    if not 0 <= s_value <= 255:
                        return 'Neither'
                    if str(s_value) != s[i]:
                        return 'Neither'
                return 'IPv4'
        else:
            if ':' in queryIP:
                s = queryIP.split(':')
                if len(s) != 8:
                    return 'Neither'
                for i in range(8):
                    if not s[i]:
                        return 'Neither'
                    if len(s[i]) > 4:
                        return 'Neither'
                    for k in range(len(s[i])):
                        if not '0' <= s[i][k] <= '9' and (not 'A' <= s[i][k] <= 'F') and (not 'a' <= s[i][k] <= 'f'):
                            return 'Neither'
                return 'IPv6'
            else:
                return 'Neither'

data = Solution()
queryIP = "172.16.254.1"
print(data.validIPAddress(queryIP))
queryIP = "192.168.01.1"
print(data.validIPAddress(queryIP))
queryIP = "192.168.1.00"
print(data.validIPAddress(queryIP))
queryIP = "192.168@1.1"
print(data.validIPAddress(queryIP))
queryIP = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
print(data.validIPAddress(queryIP))
queryIP = "2001:db8:85a3:0:0:8A2E:0370:7334"
print(data.validIPAddress(queryIP))
queryIP = "2001:0db8:85a3::8A2E:037j:7334"
print(data.validIPAddress(queryIP))
queryIP = "02001:0db8:85a3:0000:0000:8a2e:0370:7334"
print(data.validIPAddress(queryIP))